<?php
/**
 * Outputs data to user on request
 *
 * Somewhat like a template switch
 **/


if( !is_string($_REQUEST['type']) ) {
  // error BREAK
}

switch( $_REQUEST['type'] ) {
  case 'POST':
          echoPosts(); break;
  case 'THREAD':
          echoThreads(); break;
  case 'FORA':
          echoFora(); break;
  default:
          echoFora(); break;
}

// again, abstraction beckons us
function echoPosts() {
  require_once 'db/db.php'; // for default_increment();
  require_once 'db/get/post.php';

  if( $_REQUEST['tnum'] < 0 ) {
    die( "BREAKAGE" ); // BREAKAGE
  }
  $tnum = (int)$_REQUEST['tnum'];
  $start = (int)$_REQUEST['start'];
  $inc = ((int)$_REQUEST['inc'] > 0) ? (int)$_REQUEST['inc'] : default_increment();
  
  $posts = getPosts( $tnum, $start, $inc );
  $count = postCount( $tnum );

  require_once 'tpl/use/ShowPosts.php';
  skin_ShowPosts( $tnum, $posts, $count, $start, $inc );

  $posts = NULL;
}
function echoThreads() {
  require_once 'db/get/thread.php';

  if( $_REQUEST['fnum'] < 0 ) {
    die( "BREAKAGE" ); // BREAKAGE
  }
  $fnum = (int)$_REQUEST['fnum'];
  $start = (int)$_REQUEST['start'];
  $inc = ((int)$_REQUEST['inc'] > 0) ? (int)$_REQUEST['inc'] : default_increment();

  $count = threadCount($fnum);
  $threads = getThreads( $fnum, $start, $inc );

  require_once 'tpl/use/ShowThreads.php';
  skin_ShowThreads( $fnum, $threads, $count, $start, $inc );

  $threads = NULL;

}
function echoFora() {
  require_once 'db/db.php'; // for default_increment();
  require_once 'db/get/forum.php';

  $start = (int)$_REQUEST['start'];
  $end = ((int)$_REQUEST['inc'] > 0) ? (int)$_REQUEST['inc'] : default_increment();

  $fora = getFora( null, $start, $end );

  require_once 'tpl/use/ShowFora.php';
  skin_ShowFora( $fora );
}

?>

